<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('用户列表')" />
	<style type="text/css">
		label.layui-form-label {width: 95px;padding-right: 0px;}
	</style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	    <div class="north">
	        <div class="north-content">
	            <form>
					<th:block th:include="include :: searchTop" />
				</form>
	        </div>
	    </div>
	    <div class="mid-content">
	        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	    </div>
	</div>
</div>
<div id="form_pass" style="padding:10px 60px 10px 10px;display:none;">
<form id="form-user-resetPwd" class="layui-form post_form" lay-filter="fform">
	<input type="hidden" name="userId" id="userId" value="">
	<input type="hidden" name="upType" value="resetpwd">
	<div class="layui-form-item">
		<label class="layui-form-label">新密码：</label>
		<div class="layui-input-block">
		<input type="password" id="newPwd" name="newPwd" autocomplete="off" class="layui-input" value="">
		</div>
	</div>
</form>
</div>
<div id="form_d" style="padding:10px 60px 10px 10px;display:none;">
	<form class="post_form">
		<div id="dhtransfer" class="demo-transfer"></div>
	</form>
</div>
<th:block th:include="include :: footer" />
<script type="text/html" id="dropdown_userState">
    <select name="userState" id="userState" lay-filter="select" fft="t_dropdown">
		<option value="">请选择</option>
		<option value="试用">试用</option>
		<option value="在职">在职</option>
		<option value="离职">离职</option>
	</select>
</script>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
        <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn" shiro:hasPermission="system:user:add">
			<i class="fa fa-plus"></i> 新增
        </div>
		<div class="layui-btn layui-btn-danger layui-table-tools" lay-event="deletebatch" shiro:hasPermission="system:user:delete">
    		<i class="fa fa-remove"></i> 删除
		</div>
		<div class="layui-btn layui-table-tools" style="background:#5FB878" lay-event="exportbtn" shiro:hasPermission="system:user:export">
			<i class="fa fa-download"></i> 导出
        </div>
    </div>
</script>
<script type="text/html" id="barDh">
    <a class="layui-btn layui-btn-xs fa fa-edit" lay-event="edit" shiro:hasPermission="system:user:edit" title="编辑"></a>
    <a class="layui-btn layui-btn-danger layui-btn-xs fa fa-remove" lay-event="del" shiro:hasPermission="system:user:delete" title="删除"></a>
    <a class="layui-btn layui-btn-danger layui-btn-xs fa fa-wrench" lay-event="editpwdpost" shiro:hasPermission="system:user:edit" style="background: brown" title="重置密码"></a>
	<a class="layui-btn layui-bg-blue layui-btn-xs fa fa-street-view" lay-event="roleSet"  shiro:hasPermission="system:userbindrole:add" title="分配角色"></a>
	<a class="layui-btn layui-bg-orange layui-btn-xs fa fa-group" lay-event="dataSet"  shiro:hasPermission="system:userandrolejurisdiction:view" title="数据权限"></a>
	<a class="layui-btn layui-bg-cyan layui-btn-xs fa fa-cogs" lay-event="funSet"  shiro:hasPermission="system:userandrolejurisdiction:view" title="功能权限"></a>
</script>
<script th:inline="javascript">
    /*<![CDATA[*/
    var gridColumns = [[${gridColumns}]];
    var k_fields =[[${fields}]];
	var moduleTable=[[${moduleTable}]];
    /*]]>*/
</script>
 <script type="text/javascript">
 var $,layer,form,table,util,transfer,laydate,wherestr={};
 layui.use(['laydate', 'table','form','layer','jquery','util', 'transfer'], function () {
	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,transfer = layui.transfer,util = layui.util;
	//实例调用
	transfer.render({
	    elem: '#dhtransfer'
	    ,data: []
		,value: []
		,title: ['未选角色', '已选角色']
	    ,id: 'roleSelect' //定义唯一索引
	})
	$.tablelist.init({
		elem: '#dhtable'
		,url: "/system/user/list"	
		,initSort: {field: 'userId',type: 'asc'}
		,sort:true
		,totalRow: gridColumns.totalRow
   		,cols: [gridColumns.gridBody
		]
		,toolbar: '#toolbar'
		,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}]
		,height:'full-' + ( $('.north').height()+36),
	});

	//头工具栏事件
	table.on('toolbar(ftable)', function(obj){
	    switch(obj.event){
	    	case 'addbtn':
				parent.layui.index.openTabsPage('/system/user/add', '用户信息-新增');
	    	break;
	    	case 'deletebatch':
	    		var checkStatus = table.checkStatus('dhtable')
	    	      ,data = checkStatus.data,postStr = [];
	    		$.each(data,function(i,v){
	    			postStr.push({'userId':v.userId});
	    		});
	    		$.operate.remove('确定要删除么？','/system/user/delete',{'userInfoItems':JSON.stringify(postStr)},function(result){
	            	layer.closeAll();
	            	table.reload('dhtable', {url: "/system/user/list",page:{curr: 1}});
	            });
	    	break;
	    	case 'fieldSet':
	    		filedSet(moduleTable);
         	break;
	    };
	});
	//监听工具条
    table.on('tool(ftable)', function (obj) {
        var data = obj.data;
        switch(obj.event){
        	case 'del':
        		$.operate.remove('确定要删除么？','/system/user/delete',{'userInfoItems':JSON.stringify([{'userId':data.userId}])},function(result){
                	layer.closeAll();
                	table.reload('dhtable', {url: "/system/user/list",page:{curr: 1}});
                });
        		break;
        	case 'edit':
        		parent.layui.index.openTabsPage('/system/user/edit?userId='+data.userId, '用户信息-编辑');
        		break;
        	case 'editpwdpost':
        		$("#userId").val(data.userId);
        		$("#newPwd").val('');
            	layer.open({
        			type: 1,
        			area: ['400px', '180px'],
        			offset: '10%',
        			title: '重置密码 - '+data.userName+ '('+data.userId+')' ,
        			shade: 0.6,
        			maxmin: true,
        			content: $('#form_pass'),
        			btn: ['保存', '取消'],
        			yes: function(index){
        				$.operate.post('/system/user/editpwdpost',$("#form-user-resetPwd").serialize(),function(res){});
        				layer.closeAll();
        			}
        		}); 
        		break;
        	case 'roleSet':
        		var roleData = [], roleSelect = [];
            	$.get('/system/user/userbindrolelist?userId='+data.userId,function(data,status){
            		if(data.code == 0){
            			transfer.reload('roleSelect', {
              	        	data: data.dataAll
              	        	,value: data.dataSelect
              	      	})
            		}
            	});
            	layer.open({
        			type: 1,
        			area: ['600px', '480px'],
        			offset: '10%',
        			title: '分配',
        			shade: 0.6,
        			maxmin: true,
        			content: $('#form_d'),
        			btn: ['保存', '取消'],
        			yes: function(index){
        				var postData = transfer.getData('roleSelect'); //获取右侧数据
        				var postSelectData = [];
        				if(postData.length > 0){
        					$.each(postData,function(i,v){
        						postSelectData.push({'guid':v.value});
            				})
        				}
        				$.operate.post('/system/user/adduserrolepost',{'userId':data.userId,'infoItems':JSON.stringify(postSelectData)},function(res){});
        				layer.closeAll();
        			}
        		});
        		break;
        	case 'dataSet':
        		$.modal.openFull('分配数据权限 -【'+data.userName+'】','/system/user/userandrolejurisdictionfordata?userId='+data.userId, function(index){
           		 var res = window["layui-layer-iframe" + index].callbackdata();
               		$.operate.post('/system/userandrolejurisdiction/fordataeditpost',{'infoItems':JSON.stringify(res),'upType':'formodule'},function(result){
                		/* setTimeout(function(){
                            window.location.reload();
                        }, 1000); */
                		});
           	 	})
        		break;
        	case 'funSet':
        		$.modal.openFull('分配功能权限 -【'+data.userName+'】','/system/user/userandrolejurisdictionformodule?userId='+data.userId, function(index){
    	   			var res = window["layui-layer-iframe" + index].callbackdata();
    	   			$.operate.post('/system/userandrolejurisdiction/formoduleeditpost',{'infoItems':JSON.stringify(res),'upType':'formodule'},function(result){
    	    		/* setTimeout(function(){
    	                window.location.reload();
    	            }, 1000); */
    	    		});
    		 	})
        		break;
        }
    });
  	//监听排序事件 
    table.on('sort(ftable)', function(obj){
    	$.tablelist.sort('dhtable',obj);
    });
    form.on('switch(fdeleted)', function(data){
		if(data.elem.checked){
			$("#deleted1").val(0);
		}else{
			$("#deleted1").val(1);
		}
	})
  	//搜索按钮
 	$('#btn-search').on('click', function () {
 		$.each(wherestr,function(i,v){$("#"+i).val()?wherestr[i]=$("#"+i).val():wherestr[i]='';});//动态获取条件的值
        table.reload('dhtable', {page: {curr: 1},where:wherestr});
     });
 	//监听下拉框——添加条件
 	form.on('select(fft)', function(obj){
 		addMore(this);
 	});
})
 </script>
</body>
</html>